/*Copyright (C) 2009 - 2011 MASSART GAUTHIER and Careil Baptiste

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

/*initialisation des constantes*/
const GameName LOG_BANTUMI 			= "bantumi.err.log";
const GameName LOG_CHIFUMI 			= "chifumi.err.log";
const GameName LOG_DAMES				= "dames.err.log";
const GameName LOG_EXCIT				= "excit.err.log";
const GameName LOG_MORPION			= "morpion.err.log";
const GameName LOG_PENDU				= "pendu.err.log";
const GameName LOG_PLUSOUMOINS	= "plus_ou_moins.err.log";
const GameName LOG_POUSSECAISSE	= "pousse_caisses.err.log";
const GameName LOG_SDL_mixer		= "SDL_mixer.err.log";
const GameName LOG_SNAKE				= "snake.err.log";
const GameName LOG_TETRIS				= "tetris.err.log";
const GameName LOG_TOURSDEHANOI	= "tours_de_hanoi.err.log";
const GameName LOG_DEFAULT			= "erreur.log";

/*fonction log*/
void Log_full(const GameName gameName, const char *errStr, const int errInt) {
	FILE *logFile = NULL;

	/*ouverture du fichier log en mode append*/
	logFile = fopen(gameName, "a");
	/*test d'ouverture*/

	if(logFile != NULL) {
		/* Il faudra laisser fputs ici */
		if(fputs(errStr, logFile) == EOF) {
			/*erreur lors de l'écriture*/
			perror("Impossible d'écrire dans le fichier log ");
		}

		if(fprintf(logFile, " : %i", errInt) < 0) {
			perror("Impossible d'écrire dans le fichier log ");
		}

		if(fputc('\n', logFile) == EOF) {
			/*erreur lors de l'écriture*/
			perror("Impossible d'écrire dans le fichier log ");
		}

		fclose(logFile);
	}
	else {
		/*ouverture échouée*/
		perror("Impossible d'ouvrir le fichier de log ");
	}
}

